/*
 * wdog.c
 *
 *  Created on: 2020年12月28日
 *      Author: Administrator
 */
#include "em_cmu.h"
#include "em_wdog.h"
#include "bsp_wdog.h"
/**************************************************************************//**
 * @brief Watchdog initialization 喂狗 WDOG_Feed();
 *****************************************************************************/
void bsp_WDOGInit(void)
{
    // Enabling clock to the interface of the low energy modules (including the Watchdog)
    CMU_ClockEnable(cmuClock_HFLE, true);

    // Watchdog Initialize settings
    WDOG_Init_TypeDef wdogInit = WDOG_INIT_DEFAULT;
    wdogInit.debugRun = true;
    wdogInit.em3Run = true;
    wdogInit.em2Run = true;
    wdogInit.clkSel = wdogClkSelULFRCO;     //1KHz时钟源
    wdogInit.perSel = wdogPeriod_2k; // 2049 clock cycles of a 1kHz clock  ~2 seconds period

    // Initializing watchdog with chosen settings
    WDOG_Init(&wdogInit);
}

//void ResetCause(void)
//{
//    // Store the cause of the last reset, and clear the reset cause register
//    sync.resetCause = RMU_ResetCauseGet();
//    // Clear Reset causes so we know which reset occurs the next time
//    RMU_ResetCauseClear();
//}
//
//void ReportResetCause(void)
//{
//    if(sync.resetCause & RMU_RSTCAUSE_PORST)
//        DEBUG("Power on Reset");
//    if(sync.resetCause & RMU_RSTCAUSE_AVDDBOD)
//        DEBUG("Brown Out Detector AVDD Reset");
//    if(sync.resetCause & RMU_RSTCAUSE_DVDDBOD)
//        DEBUG("Brown Out Detector DVDD Reset");
//    if(sync.resetCause & RMU_RSTCAUSE_DECBOD)
//        DEBUG("Brown Out Detector Decouple Domain Reset");
//    if(sync.resetCause & RMU_RSTCAUSE_EXTRST)
//        DEBUG("External Pin Reset");
//    if(sync.resetCause & RMU_RSTCAUSE_SYSREQRST)
//        DEBUG("System Request Reset");
//    if(sync.resetCause & RMU_RSTCAUSE_WDOGRST)
//        DEBUG("Watchdog Reset");
//    if(sync.resetCause & RMU_RSTCAUSE_EM4RST)
//        DEBUG("EM4 Reset");
//}
